package com.heima.article.controller.v1;

import com.heima.article.service.ArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 10161
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * 加载页面
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(ArticleHomeDto articleHomeDto) {
        List<ApArticle> apArticles =
                articleService.loadArticleList(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return ResponseResult.okResult(apArticles);
    }

    /**
     * 上滑加载更多
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadmore(ArticleHomeDto articleHomeDto) {
        List<ApArticle> apArticles =
                articleService.loadArticleList(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
        return ResponseResult.okResult(apArticles);

    }

    /**
     * 下滑刷新加载最新
     *
     * @param articleHomeDto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadnew(ArticleHomeDto articleHomeDto) {
        List<ApArticle> apArticles =
                articleService.loadArticleList(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_NEW);
        return ResponseResult.okResult(apArticles);

    }



}
